package com.hbvtc.xxxy.nikeSale.daos;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.hbvtc.xxxy.nikeSale.models.GoodsShop;
import com.hbvtc.xxxy.nikeSale.utils.DbManager;

public class GoodsDao {
	private static Connection conn = null;
	private static PreparedStatement pst = null;
	private static ResultSet rs = null;
	private static ResultSet res;
	
	//通过管理员的账号查询
	public boolean getBySalesmanId(int id) throws SQLException{
		String sql="select SalesmanId from salesman where SalesmanId=?";
		conn=DbManager.getconn();
		pst=conn.prepareStatement(sql);
		pst.setInt(1,id);
		res=pst.executeQuery();
		int i=0;
		while (res.next()) {
				i=res.getInt("SalesmanId")	;	
		}
		if(i>0){
			return false;
		}else {
			return true;
		}
	}
	//通过商品id查询
	public boolean getByGoodsId(int id) throws SQLException{
		String sql="select GoodsID from goods where GoodsID=?";
		conn=DbManager.getconn();
		pst=conn.prepareStatement(sql);
		pst.setInt(1,id);
		res=pst.executeQuery();
		int i=0;
		while (res.next()) {
				i=res.getInt("GoodsID")	;	
		}
		if(i>0){
			return false;
		}else {
			return true;
		}
	}
	//增加商品信息
	public void AddGoods(GoodsShop goodsShop) throws SQLException {
		conn = DbManager.getconn();
		String sql = "insert into goods (GoodsID,GoodsName,SalePrice,StockNum)values(?,?,?,?)";	    
		pst = conn.prepareStatement(sql);
		pst.setInt(1, goodsShop.getGoodsID());
		pst.setString(2, goodsShop.getGoodsName());
		pst.setDouble(3, goodsShop.getSalePrice());
		pst.setInt(4, goodsShop.getStockNum());	
//		pst.setString(5, goodsShop.getTypeID());	
		pst.execute();// 执行SQL语句pst		
	}
}
